$(function () {
    findAll();
    findCompany();
})

function findCompany() {
    let data=myAjax("/common","get",{});

    setcompanyModelData(data[0].object.companyModel);
    setnavModelListData(data[0].object.navModelList);

}

function findAll() {
    let data = myAjax("/home", "get", {});
    setHomeNewsData(data[0].object.newsModelList);
    setproductModelListData(data[0].object.productModelList);

}

function setcompanyModelData(data) {

    $("#logo").attr("src", data.logo);
    $("#phone").html(data.phone);
    $("#ad").html(data.ad);
    $("#net").html(data.net);
    $("#email").html('邮箱:' + data.email + '联系电话: ' + data.linePhone + '(座机)');
    $("#address").html(data.address);
    $("#version").html(data.version);
}

function setnavModelListData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '            <a href="' + data[i].href + '">\n' +
            '                <div>' + data[i].name + '</div>\n' +
            '            </a>';
    }
    $("#navList").html(html);
}

function setproductModelListData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        if (i == 0) {
            html += '<div class="floatLeft home-product">\n';
        } else {
            html += '<div class="floatRight home-product">\n';
        }
        html += '                <div><img src="' + data[i].imgHref + '" height="300" width="300"/></div>\n' +
            '                <div>' + data[i].title + '</div>\n' +
            '                <div>' + data[i].content + '</div>\n' +
            '            </div>';
    }
    $("#productList").html(html);

}

//新闻赋值
function setHomeNewsData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += ' <div>\n' +
            '     <a href="#"><h5>' + data[i].title + '</h5></a>\n' +
            '     <a href="#"><p>' + data[i].content + '</p></a>\n' +
            ' </div>';
    }
    $("#homeNewsList").html(html);
}